package cn.it.service.impl;

import cn.it.dao.CompanyDao;
import cn.it.entity.PageResult;
import cn.it.entity.QueryPageBean;
import cn.it.pojo.Company;
import cn.it.service.CompanyService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = CompanyService.class)
@Transactional
public class CompanyServiceImpl implements CompanyService {


    @Autowired
    private CompanyDao companyDao;

    @Override
    public void addAddress(Company company) {
        companyDao.addAddress(company);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        String queryString = queryPageBean.getQueryString();
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();

        PageHelper.startPage(currentPage, pageSize);

        Page<Company> page = companyDao.selectByCondition(queryString);
        List<Company> list = page.getResult();
        long total = page.getTotal();

        return new PageResult(total, list);
    }

    @Override
    public void delete(Integer id) {
        companyDao.deleteId(id);
    }

    @Override
    public List<Company> findAll() {
        return companyDao.findAll();
    }
}
